import Detail from "@/pages/Detail/index";
import Home from "@/pages/Home/index";
import Login from "@/pages/Login/index";
import Search from "@/pages/Search/index";
import Book from "@/pages/Book/index";
import Register from "@/pages/Register/index";
import AddCartSuccess from '@/pages/addCartSuccess'
import ShopCart from '@/pages/shopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'

//二级路由
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'
export default [
        {
            path:'/home',
            component:Home,
            meta:{show:true}
        },
        {
            path:'/login',
            component:Login,
            meta:{show:false}
        },
        {
            path:'/search',
            component:Search,
            meta:{show:true},
            name:'search'
        },
        {
            path:'/book',
            component:Book,
            meta:{show:true},
            name:'book'
        },
        {
            path:'/register',
            component:Register,
            meta:{show:false}
        },
        //重定向，在项目跑起来的时候，立马定向到首页
        {
            path: '*',
            redirect:'/home'
        },
        {
            path:'/detail/:skuId?',
            component:Detail,
            //路由元信息,控制当前路由是否需要Footer组件
            meta:{show:true}
        },
        {
        path:'/addcartsuccess',
        component:AddCartSuccess,
        meta:{show:true},
        name: 'addcartsuccess'
        },
    {
        path:'/shopcart',
        component:ShopCart,
        meta:{show:true},
    },
    {
        path:'/trade',
        component:Trade,
        meta:{show:true},
        //路由独享守卫
        beforeEnter:(to,from,next)=>{
            if (from.path=="/shopcart"){
                next();
            }else {
                next(false);
            }
        }
    },
    {
        path:'/pay',
        component:Pay,
        meta:{show:true},
        //路由独享守卫
        beforeEnter:(to,from,next)=>{
            if (from.path=="/trade"){
                next();
            }else {
                next(false);
            }
        }
    },
    {
        path:'/paysuccess',
        component:PaySuccess,
        meta:{show:true},
    },
    {
        path:'/center',
        component:Center,
        meta:{show:true},
        child:[
            {
                path: 'myorder',
                components:MyOrder
            },
            {
                path:'grouporder',
                components: GroupOrder
            },
            {
                path: 'center',
                redirect:'/center/myorder'
            }
        ]
    },
]
